package com.own.pages;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import com.own.app.OwnSession;
import com.own.core.html.page.OwnWebPage;
import com.own.core.html.tabs.OwnAbstractTab;
import com.own.core.html.tabs.OwnAjaxTabbedPanel;
import com.own.core.html.tabs.SubTab;
import com.own.core.object.admin.User;
 
import com.own.core.object.admin.pages.Page;
import com.own.core.operation.DbOperation;
import com.own.core.util.Model.OwnResourceModel;
 

@AuthorizeInstantiation("ADMIN")
public class Main extends OwnWebPage {
	User user;

	public Main() {
 
		List tabs = new ArrayList();
		user = ((OwnSession) getSession()).getUser();
		Map paraMap = new HashMap();
		paraMap.put("userId",user.getId());
		List mainPage = DbOperation.getME().executeNamedQuery(
				"page.loadMainPage",paraMap);

		for (Object obj : mainPage) {
			final Page page = (Page) obj;

			tabs.add(new OwnAbstractTab((new OwnResourceModel(page.getName()))) {

				public Panel getPanel(String panelId) {
					SubTab sub = new SubTab(panelId);
					sub.setMainPage(page);
					sub.initPanel();
					return sub;
				}

			});
		}

		OwnAjaxTabbedPanel mainTab = new OwnAjaxTabbedPanel("tabs", tabs);
		mainTab.add(new AttributeModifier("class", true, new Model("maintab")));
		add(mainTab);

	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
